home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / lisp / eulisp / feel0_89.lha / Feel / Src / system_p.h < prev    next >
C/C++ Source or Header  |  1993-06-30  |  7KB  |  251 lines

  1. /* ******************************************************************** */
  2. /* system.h          Copyright (C) Codemist and University of Bath 1989 */
  3. /*                                                                      */
  4. /* Environment specific code                                           */
  5. /* ******************************************************************** */
  6.  
  7. /*
  8.  * $Id: system_p.h,v 1.7 1992/11/26 16:11:33 pab Exp $
  9.  *
  10.  * $Log: system_p.h,v $
  11.  * Revision 1.7  1992/11/26  16:11:33  pab
  12.  * _ANY fixes
  13.  *
  14.  * Revision 1.5  1992/06/11  23:58:39  pab
  15.  * fixed includes
  16.  *
  17.  * Revision 1.4  1992/05/28  16:10:42  rjb
  18.  * comment text after #endif
  19.  *
  20.  * Revision 1.3  1992/01/29  13:49:32  pab
  21.  * sysV fixes
  22.  *
  23.  * Revision 1.2  1991/09/11  12:07:47  pab
  24.  * 11/9/91 First Alpha release of modified system
  25.  *
  26.  * Revision 1.1  1991/08/12  16:50:06  pab
  27.  * Initial revision
  28.  *
  29.  * Revision 1.7  1991/05/16  11:31:20  pab
  30.  * 'C' garbage collector additions
  31.  *
  32.  * Revision 1.5  1991/02/28  13:53:19  kjp
  33.  * Fixed fopen/close macros in sysv - added GC state codes.
  34.  *
  35.  * Revision 1.4  1991/02/13  18:26:05  kjp
  36.  * Pass.
  37.  *
  38.  */
  39.  
  40. /*
  41.  * System specific prototypes...
  42.  *
  43.  * (see '.c' for details)
  44.  */
  45.  
  46. #ifndef SYSTEM_P_H
  47.  
  48. #define SYSTEM_P_H
  49.  
  50. /*
  51.  * Interfaces...
  52.  */
  53.  
  54. extern int system_running_processors;
  55. #define RUNNING_PROCESSORS() (system_running_processors)
  56.  
  57. /* ******************************************************************** */
  58. /*                             System V                                 */
  59. /* ******************************************************************** */
  60.  
  61. #ifdef MACHINE_SYSTEMV
  62.  
  63. extern int system_scheduler_number;
  64.  
  65. #define system_fopen(f,m) (fopen(f,m))
  66. #define system_fclose(f)  (fclose(f))
  67.  
  68. extern int system_read(int,char*,int);
  69.  
  70. extern char *system_malloc(int);
  71. extern char *system_static_malloc(int);
  72. /*
  73. #define system_allocate_semaphore(addr) (*(addr)=semget(IPC_PRIVATE,1,NULL))
  74. #define system_initialise_semaphore(addr) semctl(*(addr),0,SETVAL,1)
  75. #define system_open_semaphore(addr) semop(*(addr),&system_sem_handler,1)
  76. #define system_close_semaphore(addr) semctl(*(addr),0,SETVAL,1)
  77. */
  78.  
  79. extern void system_allocate_semaphore(SystemSemaphore *);
  80. extern void system_initialise_semaphore(SystemSemaphore *);
  81. extern void system_open_semaphore(LispObject *,SystemSemaphore *);
  82. extern void system_close_semaphore(SystemSemaphore *);
  83. extern int system_maybe_open_semaphore(LispObject *, SystemSemaphore *);
  84.  
  85. extern LispObject system_thread_rig(LispObject*,LispObject);
  86. extern LispObject system_thread_start(LispObject);
  87. extern LispObject system_thread_call(LispObject);
  88. extern LispObject system_thread_suspend(void);
  89. extern LispObject system_thread_reschedule(void);
  90. extern void system_thread_abort(void);
  91.  
  92. #define GC_sync_test() \
  93.           (SYSTEM_GLOBAL_VALUE(GC_state) == GC_SINKING \
  94.             ? ((void) garbage_collect(stacktop),TRUE) \
  95.         : FALSE)
  96.  
  97. extern SYSTEM_GLOBAL(SystemSemaphore,atomic_semaphore);
  98.  
  99. #define ATOMIC(stacktop,x)            \
  100. {                    \
  101.   system_open_semaphore(stacktop,&SYSTEM_GLOBAL_VALUE(atomic_semaphore)); \
  102.   x;                    \
  103.   system_close_semaphore(&SYSTEM_GLOBAL_VALUE(atomic_semaphore)); \
  104. }
  105.  
  106.  
  107. #endif
  108.  
  109. /* ******************************************************************** */
  110. /*                            Any Machine                               */
  111. /* ******************************************************************** */
  112.  
  113. #ifdef MACHINE_ANY
  114.  
  115. #ifndef PROCESSORS
  116. #define PROCESSORS (1)
  117. #endif
  118.  
  119. #define system_fopen(f,m) (fopen(f,m))
  120. #define system_fclose(f)  (fclose(f))
  121.  
  122. #define system_read(a,b,c) (read(a,b,c))
  123.  
  124. extern char *system_malloc(int);
  125. #ifdef CGC
  126. #define  system_malloc(n) gc_malloc(n)
  127. #define system_static_malloc(n) gc_malloc(n)
  128. #else
  129. extern char *system_static_malloc(int);
  130. #endif
  131.  
  132. #define system_allocate_semaphore(addr) IGNORE(*addr)
  133. #define system_initialise_semaphore(addr)
  134. #define system_open_semaphore(x,addr)
  135. #define system_close_semaphore(addr)
  136. #define system_maybe_open_semaphore(x,addr) (1)
  137.  
  138. extern int system_scheduler_number;
  139.  
  140. /* Place where 'system_thread' calls would be */
  141.  
  142. #define GC_sync_test()
  143. #define ATOMIC(s,x) x
  144. #endif
  145.  
  146. /* ******************************************************************** */
  147. /*                               BSD                                    */
  148. /* ******************************************************************** */
  149.  
  150. #ifdef MACHINE_BSD
  151.  
  152. extern int system_scheduler_number;
  153.  
  154. #define system_fopen(f,m) (fopen(f,m))
  155. #define system_fclose(f)  (fclose(f))
  156.  
  157. #define system_read(a,b,c) (read(a,b,c))
  158.  
  159. extern char *system_malloc(int);
  160. extern char *system_static_malloc(int);
  161.  
  162. #define system_allocate_semaphore(addr) (*(addr)=1)
  163. #define system_initialise_semaphore(addr) (*(addr)=1)
  164. #define system_open_semaphore(x,addr) \
  165.           { \
  166.         if (*(addr)!=1){ \
  167.           fprintf(stderr,"Unexpected value of semaphore"); \
  168.          \
  169.         } \
  170.         *(addr) = 0; \
  171.       }
  172. #define system_close_semaphore(addr) (*(addr)=1)
  173. #define system_maybe_open_semaphore(x,addr) (*(addr) == 1 ? *addr = 0,1 : 0)
  174.  
  175. extern LispObject system_thread_rig(LispObject*,LispObject);
  176. extern LispObject system_thread_start(LispObject);
  177. extern LispObject system_thread_call(LispObject);
  178. extern LispObject system_thread_suspend(void);
  179. extern LispObject system_thread_reschedule(void);
  180. extern void system_thread_abort(void);
  181.  
  182. #define GC_sync_test()
  183. #define ATOMIC(s,x) x
  184. #endif
  185.  
  186. /* Thread system prototypes... */
  187.  
  188. extern SYSTEM_GLOBAL_ARRAY1(LispObject,system_scheduler_threads,MAX_PROCESSORS);
  189.  
  190. /* Initialisation prototypes... */
  191.  
  192. extern void runtime_initialise_system(void);
  193. extern void system_initialise_scheduler(void);
  194. extern void system_lisp_exit(int);
  195.  
  196. #define THREAD_LIMBO (0)
  197. #define THREAD_READY (1)
  198. #define THREAD_RUNNING (2)
  199. #define THREAD_RETURNED (3)
  200. #define THREAD_ABORTED (4)
  201.  
  202. #define GC_SINKING    (0)
  203. #define GC_REGISTERED (1)
  204. #define GC_MARKED     (2)
  205. #define GC_DONE       (3)
  206.  
  207. extern SYSTEM_GLOBAL(int,GC_state);
  208.  
  209. #ifndef SYSTEM_MAX_SHARED_SIZE
  210. #define SYSTEM_MAX_SHARED_SIZE (1*1024*1024)
  211. #endif
  212.  
  213. #ifdef WITH_PROFILING
  214.  
  215. #include <sys/time.h>
  216.  
  217. #define PROFILE_RUNNING  ('R')
  218. #define PROFILE_IDLE     ('I')
  219. #define PROFILE_GC_START ('G')
  220. #define PROFILE_GC_END   ('E')
  221. #define PROFILE_BLOCKED  ('B')
  222.  
  223. #define PROFILE(x) x
  224.  
  225. #define DEF_PROFILE_TIMER(name) struct itimerval *name
  226.  
  227. #define INIT_PROFILE_TIMER(name) \
  228.           name \
  229.             = (struct itimerval *) \
  230.                 system_static_malloc(sizeof(struct itimerval)); \
  231.           name->it_interval.tv_sec = 0; \
  232.           name->it_interval.tv_usec = 10; \
  233.           name->it_value.tv_sec = 0; \
  234.           name->it_value.tv_usec = 0; \
  235.           setitimer(ITIMER_REAL,name,NULL); 
  236.  
  237. #define PROFILE_TIME(name) (name->it_value.tv_sec)
  238.  
  239. extern struct itimerval *system_local_timer;
  240.  
  241. #else
  242. #define PROFILE(x)
  243. #define DEF_PROFILE_TIMER(x)
  244. #define INIT_PROFILE_TIMER(x)
  245. #define PROFILE_TIME(x)
  246. #endif
  247.  
  248. #endif /* SYSTEM_P_H */
  249.  
  250.  
  251.